import csv
import os

csv_list = os.listdir('data/unofficial-indicators')
for file in csv_list:
    with open(f'data/unofficial-indicators/{file}', newline='') as csvfile:
        csvfile.readline()
        content = list(csv.DictReader(csvfile, delimiter=',', quotechar='"'))[:-2]
        col_num = len(content[0]) - 2
        eff_row = []
        for row in content[1:]:
            if list(row.values()).count('') / col_num < 0.5:
                eff_row.append(row)
    with open(f'data/aaaaa/{file}', 'w', newline='') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=content[0].keys())
        writer.writeheader()
        for row in eff_row:
            writer.writerow(row)
